package com.xiyu.service.controller.admin.infra.devops;
import com.xiyu.service.vo.infra.devops.customer.CustomerGetSingleCustomerInfoInput;
import com.xiyu.service.vo.infra.devops.customer.CustomerGetSingleCustomerInfoOutput;
import com.xiyu.service.vo.infra.devops.customer.CustomerGetServerCustomerInfoOutput;
import com.xiyu.service.vo.infra.devops.customer.CustomerGetServerCustomerInfoInput;
import com.xiyu.service.vo.infra.devops.customer.CustomerSingleGetOutput;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.vo.infra.devops.customer.CustomerUpdateInput;
import com.xiyu.service.vo.infra.devops.customer.CustomerCreateInput;
import com.xiyu.service.vo.infra.devops.customer.CustomerPageQueryOutput;
import com.xiyu.service.vo.infra.devops.customer.CustomerPageQueryInput;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import com.xiyu.service.service.infra.devops.CustomerService;

import java.util.List;

import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

@Tag(name = "客户管理")
@RestController
@RequestMapping("/infra/devops/customer")
@Validated
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询客户")
    public CommonResult<PageResult<CustomerPageQueryOutput>> pageQuery(@Valid CustomerPageQueryInput inputVO) {
        return success(customerService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增客户")
    public CommonResult<Long> create(@Valid @RequestBody CustomerCreateInput inputVO) {
        return success(customerService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新客户")
    public CommonResult<Boolean> update(@Valid @RequestBody CustomerUpdateInput inputVO) {
        return success(customerService.update(inputVO));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "删除客户")
    @Parameter(name = "id", description = "客户主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("id") Long id) {
        return success(customerService.deleted(id));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个客户")
    @Parameter(name = "id", description = "客户主键ID", example = "")
    public CommonResult<CustomerSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(customerService.singleGet(id));
    }

    @PermitAll
    @PostMapping("/get-server-customer-info")
    @Operation(summary = "根据服务器IP和项目查询")
    public CommonResult<List<CustomerGetServerCustomerInfoOutput>> getByIpAndProject(@Valid @RequestBody CustomerGetServerCustomerInfoInput inputVO, HttpServletRequest request) {
        return success(customerService.getServerCustomerInfo(request, inputVO));
    }

    @PermitAll
    @PostMapping("/get-single-customer-info")
    @Operation(summary = "获取单个客户信息")
    public CommonResult<CustomerGetSingleCustomerInfoOutput> getSingleCustomerInfo(@Valid @RequestBody CustomerGetSingleCustomerInfoInput inputVO) {
        return success(customerService.getSingleCustomerInfo(inputVO));
    }

}
